﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Activation;
using Webbshop.ServiceReference1;

namespace Webbshop
{
    /// <summary>
    /// Local service that is handles some connections between the ASP.NET and the WCF
    /// Mainly a workaround in the use of dataconnections in the AJAX auto completion
    /// </summary>
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Autocomplete
    {
        /// <summary>
        /// Local Service that handle some connections to WCF. Mainly a workaround in the use of AJAX tools
        /// </summary>
        /// <param name="prefixText">user searchword</param>
        /// <param name="count">unused (inherit from AJAX:Extension standard)</param>
        /// <returns>Array of product names that contains the prefixText</returns>
        [OperationContract]
        public string[] GetCompletionList(string prefixText, int count)
        {
            var proxy = new ShoppeServiceClient();
            string[] result = {};
            try
            {
                result = proxy.GetCompletionList(prefixText);
            }
            finally {
                proxy.Close();
            }
            return result;
        }
    }
}
